/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "S_模型.h"

#include "底层绘图/底层绘图框架.h"

#include "物体/物体.h"



S_物体* f_ob_创建基准网格线(S_设备环境& ctx) {
	S_物体* 基准网格线 = f_ob_创建网格物体(ctx);
	基准网格线->m_Name = u"场景视口网格";
	基准网格线->m_视口显示模式 = 1<<0 | 1<<1 | 1<<2;


	S_Mesh* 基线 = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	S_Mesh* 主线 = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	S_Mesh* 辅线 = f_surface_创建网格对象(nullptr, ctx, false, E_网格数据枚举::e_Mesh_Vulkan);
	f_ob_set数据槽数量(基准网格线, 3);

	f_ob_set数据(基准网格线, 基线, 0);
	f_ob_set数据(基准网格线, 主线, 1);
	f_ob_set数据(基准网格线, 辅线, 2);

	f_mesh_set绘制内存属性(基线, {});
	f_mesh_set绘制内存属性(主线, {});
	f_mesh_set绘制内存属性(辅线, {});


	f_ob_set材质(基准网格线, f_g_预设材质().g_线段材质, 0);
	f_ob_set材质(基准网格线, f_g_预设材质().g_线段材质, 1);
	f_ob_set材质(基准网格线, f_g_预设材质().g_线段材质, 2);


	int32 num = 60;
	float32 长度 = 600;

	std::vector<S_VC> 顶点;
	顶点.reserve(4);
	顶点.push_back({ { -长度, 0.0f, 0.0f }, f_PackData4X8({ 255,100,100,200 }) });
	顶点.push_back({ { 长度, 0.0f, 0.0f }, f_PackData4X8({ 255,100,100,200 }) });
	顶点.push_back({ { 0.0f, 0.0f, -长度 }, f_PackData4X8({ 100,100,255,200 }) });
	顶点.push_back({ { 0.0f, 0.0f, 长度 }, f_PackData4X8({ 100,100,255,200 }) });
	f_mesh_fill顶点数据(基线, 顶点);
	基线->m_线宽 = 1.5;


	S_RGBA8UI 线颜色 = {128,128,128,150};
	const float32 主线跨度 = 10;
	顶点.clear();
	顶点.reserve(num * 4 * 2);
	for (uint32 i = 1; i < num; ++i) {
		vec3 vx = {};

		vx.x = 长度;
		vx.z = 主线跨度 * i;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });
		vx.x = -长度;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });

		vx.x = 长度;
		vx.z = -主线跨度 * float32(i);
		顶点.push_back({ vx, f_PackData4X8(线颜色) });
		vx.x = -长度;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });



		vx.x = 主线跨度 * i;
		vx.z = 长度;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });
		vx.z = -长度;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });

		vx.x = -主线跨度 * i;
		vx.z = 长度;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });
		vx.z = -长度;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });

	}
	f_mesh_fill顶点数据(主线, 顶点);
	主线->m_线宽 = 1.5;



	线颜色 = {120,120,120,128};
	num *= 10;
	顶点.clear();
	顶点.reserve(num * 4 * 2);
	for (uint32 i = 1; i < num; ++i) {
		vec3 vx = {};

		vx.x = 长度;
		vx.z = i;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });
		vx.x = -长度;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });

		vx.x = 长度;
		vx.z = -float32(i);
		顶点.push_back({ vx, f_PackData4X8(线颜色) });
		vx.x = -长度;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });



		vx.x = i;
		vx.z = 长度;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });
		vx.z = -长度;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });

		vx.x = -float32(i);
		vx.z = 长度;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });
		vx.z = -长度;
		顶点.push_back({ vx, f_PackData4X8(线颜色) });
	}
	f_mesh_fill顶点数据(辅线, 顶点);
	辅线->m_线宽 = 0.5;


	return 基准网格线;
}


